function displayColor(e)
{
 if (! e || ! document || ! document.getElementById) return true;

 var r = 0, g = 0, b = 0;
 var v = e.value;

 var expr1 = /([0-9]+%?)[^0-9A-F]+([0-9]+%?)[^0-9A-F]+([0-9]+%?)/i;
 var expr2 = /([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])([0-9A-F]?[0-9A-F]?)/i;
 var expr3 = /([0-9A-F])([0-9A-F]?)([0-9A-F]?)/i;
 if (expr1.exec(v))
 {
  r = RegExp.$1;
  g = RegExp.$2;
  b = RegExp.$3;
  if (r.indexOf("%") >= 0) r = Math.round(parseInt(r) * 2.55);
  if (g.indexOf("%") >= 0) g = Math.round(parseInt(g) * 2.55);
  if (b.indexOf("%") >= 0) b = Math.round(parseInt(b) * 2.55);
 }
 else if (expr2.exec(v))
 {
  r = parseInt((RegExp.$1 + "00").substr(0, 2), 16);
  g = parseInt((RegExp.$2 + "00").substr(0, 2), 16);
  b = parseInt((RegExp.$3 + "00").substr(0, 2), 16);
 }
 else if (expr3.exec(v))
 {
  r = parseInt("0" + RegExp.$1 + RegExp.$1, 16);
  g = parseInt("0" + RegExp.$2 + RegExp.$2, 16);
  b = parseInt("0" + RegExp.$3 + RegExp.$3, 16);
 }

 r = Math.min(Math.max(0, r), 255);
 g = Math.min(Math.max(0, g), 255);
 b = Math.min(Math.max(0, b), 255);

 v = "#" + (r < 16 ? "0" : "") + r.toString(16) +
  (g < 16 ? "0" : "") + g.toString(16) + (b < 16 ? "0" : "") + b.toString(16);
 v = v.toUpperCase();
 document.getElementById("chex").style.backgroundColor = v;
 if (document.getElementById("vhex").firstChild)
  document.getElementById("vhex").firstChild.data = v;

 v = "rgb(" + Math.round(r) + "," + Math.round(g) + "," + Math.round(b) + ")";
 document.getElementById("cdecimal").style.backgroundColor = v;
 if (document.getElementById("vdecimal").firstChild)
  document.getElementById("vdecimal").firstChild.data = v;

 v = "rgb(" + Math.round(r / 2.55) + "%," + Math.round(g / 2.55) + "%," +
  Math.round(b / 2.55) + "%)";
 document.getElementById("cpercent").style.backgroundColor = v;
 if (document.getElementById("vpercent").firstChild)
  document.getElementById("vpercent").firstChild.data = v;

 v = "#" + (r < 1 ? "0" : Math.round(r / 17).toString(16)) +
  (g < 1 ? "0" : Math.round(g / 17).toString(16)) +
  (b < 1 ? "0" : Math.round(b / 17).toString(16));
 v = v.toUpperCase();
 document.getElementById("cshort").style.backgroundColor = v;
 if (document.getElementById("vshort").firstChild)
  document.getElementById("vshort").firstChild.data = v;

 v = "#" + (r < 1 ? "0" : (Math.round(r / 51) * 3).toString(16)) +
  (g < 1 ? "0" : (Math.round(g / 51) * 3).toString(16)) +
  (b < 1 ? "0" : (Math.round(b / 51) * 3).toString(16));
 v = v.toUpperCase();
 document.getElementById("csafe").style.backgroundColor = v;
 if (document.getElementById("vsafe").firstChild)
  document.getElementById("vsafe").firstChild.data = v;

 document.getElementById("call").style.color = r + g + b > 320 ? "black" : "white";

 return false;
}
